<?php

// +----------------------------------------------------------------------
// |Author: 翼小菜
// +----------------------------------------------------------------------
// |Description: 控制台显示内容
// +----------------------------------------------------------------------
// |更多功能可联系QQ314688769
// +----------------------------------------------------------------------
namespace api\cveadmin\controller;
use OpenApi\Annotations as OA;
use api\cveadmin\model\AssetModel;
use cmf\controller\RestAdminBaseController;
use api\cveadmin\service\UserService;
use api\cveadmin\service\AssetService;
class IndexController extends RestAdminBaseController
{
    /**
     * @OA\Tag(
     *     name="cveadmin",
     *     description="CVEAdmin后台API"
     * )
     */
    public function index(){
        $this->success('请求成功!', "portal api");
    }
    /**
    * cveadmin控制台输出
    * @throws \think\exception\DbException
    * @OA\Get(
    *     tags={"cveadmin"},
    *     path="/cveadmin/index/getServerInfo",
    *     summary="cveadmin控制台输出",
    *     description="cveadmin控制台输出",
    *     @OA\Response(
    *          response="1",
    *          description="success",
    *          @OA\JsonContent(example={"code": 1,"msg": "success","data":{
    *            "serverName": "192.168.0.115",
    *            "serverIp": "192.168.0.115",
    *            "serverSoftware": "nginx\/1.22.1",
    *            "serverOs": "Linux zero 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64",
    *            "phpVersion": "8.1.13",
    *            "cmfVersion": "8.0.1",
    *            "users": 2,
    *            "assets": 16
    *          }})
    *     ),
    *     @OA\Response(
    *          response="0",
    *          @OA\JsonContent(example={"code": 0,"msg": "error!","data":""})
    *     ),
    * )
    */  
    public function getServerInfo()
    {
        $userService = new UserService;
        $assetService = new AssetService;
        $data = [
            'serverName' => $_SERVER['SERVER_NAME'], // 获取服务器名称
            'serverIp' => $_SERVER['SERVER_ADDR'], // 获取服务器IP地址
            'serverSoftware' => $_SERVER['SERVER_SOFTWARE'], // 获取服务器软件信息
            'serverOs' =>  php_uname(),//操作系统
            'phpVersion' => phpversion(),
            'cmfVersion' => cmf_version(),
            'users'      => $userService->countUsers(),
            'assets'     => $assetService->countAssets()
        ];
        $this->success('success',$data);
    }
}
